package osmedile.intellij.util;

import java.util.Collection;

/**
 * @author Olivier Smedile
 * @version $Id: File Header.java 3 2008-03-11 08:52:55Z osmedile $
 */
public class RegexUtil {
    /**
     * Replace all string in template which are keys in replacement parameter by regex "(.*)"
     *
     * @param template
     * @param replacement
     *
     * @return
     */
    public static String transforPattern(String template, Collection<String> replacement) {
        String result = template;
        for (String key : replacement) {
            key = key.replaceAll("(\\$)", "\\\\$1");
            result = result.replace(key, "(.*)");
        }

        return result;
    }


    /**
     * Replace all chars which have a special meaning in regex to escaped chars
     *
     * @param s
     *
     * @return
     */
    public static String inhibitRegexChars(String s) {
        return s.replaceAll("(\\.|\\[|\\]|\\\\|\\||\\-|\\^|\\$|\\?|\\*|\\+|\\{|\\}|\\(|\\))", "\\\\$1");
    }
}
